package com.tg.controller;


import com.tg.pojo.entity.TgOrder;
import com.tg.pojo.entity.TgOrderDetail;
import com.tg.pojo.requestVo.OrderReq;
import com.tg.pojo.resposeVo.BaseResp;
import com.tg.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author 王兴
 * @Description
 * @Date 2022/3/28
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;


    @RequestMapping("/addOrder")
    public BaseResp addOrder(@RequestBody OrderReq orderReq, HttpServletRequest request){
        return orderService.addOrder(orderReq,request);

    }

    @RequestMapping("/findOrderByUserId")
    public BaseResp findOrderByUserId(HttpServletRequest request){
        return orderService.findOrderByUserId(request);
    }


    @RequestMapping("/cancelOrder")
    public BaseResp cancelOrder(@RequestBody Map map){
        return orderService.cancelOrder(map);

    }

    @RequestMapping("/findDetailByOrderid")
    public BaseResp findDetailByOrderid(@RequestParam("orderid") String orderid){
        return orderService.findDetailByOrderid(orderid);
    }

    @RequestMapping("/findByOrderid")
    public BaseResp findByOrderid(@RequestParam("orderid") String orderid){
        return orderService.findByOrderid(orderid);
    }

    @RequestMapping("/updateStatus")
    public BaseResp updateStatus(String orderId,Integer status){
        return orderService.updateStatus(orderId,status);
    }


    @RequestMapping("/findByStatusAndUserid")
    public BaseResp findByStatusAndUserid(@RequestBody Map map){
        return orderService.findByStatusAndUserid(map);
    }

    @RequestMapping("/findByDetailByOrderDetail")
    public BaseResp findByDetailByOrderDetail(@RequestParam("detailId") String detailId){
        return orderService.findByDetailByOrderDetail(detailId) ;
    }

    //改签方法
    @RequestMapping("/saveAndFlush")
    public BaseResp saveAndFlush(@RequestBody TgOrder tgOrder){
        return orderService.saveAndFlush(tgOrder);
    }

    @RequestMapping("/updateOrderId")
    public BaseResp updateOrderId(@RequestBody TgOrderDetail tgOrderDetail){
        return orderService.updateOrderId(tgOrderDetail);
    }

    //改签方法
    @RequestMapping("/delById")
    public BaseResp delById(@RequestParam("oldOrderId")String oldOrderId){
        return orderService.delById(oldOrderId);
    }
}
